package com.goktech.olala.core.service.impl;

import com.goktech.olala.core.resp.RespShopCartVo;
import com.goktech.olala.core.service.IShopcartService;
import com.goktech.olala.server.dao.order.ShopcartMapper;
import com.goktech.olala.server.pojo.order.Shopcart;
import com.goktech.olala.utils.RMBUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname ShopcartServiceImp
 * @Description TODO
 * @Date 2020/12/15 23:03
 * @Created by sanming
 */
@Service
public class ShopcartServiceImp implements IShopcartService {

    @Autowired
    ShopcartMapper shopcartMapper;

    @Override
    public List<Shopcart> selectCustomerId(String customerId) {
        return shopcartMapper.selectCustomerId(customerId);
    }

    @Override
    public int insert(Shopcart record) {
        return shopcartMapper.insert(record);
    }

    @Override
    public int deleteShopcart(Shopcart shopcart) {
        return shopcartMapper.deleteShopcart(shopcart);
    }

    @Override
    public Shopcart selectCollect(Long shopCartId, String customerId) {
        return shopcartMapper.selectCollect(shopCartId,customerId);
    }

    @Override
    public RespShopCartVo queryShopCartById(String shopCartId) throws Exception {
        RespShopCartVo respShopCartVo = new RespShopCartVo();
        Shopcart shopcart = shopcartMapper.selectByPrimaryKey(Long.valueOf(shopCartId));
        if(shopcart != null){
            BeanUtils.copyProperties(shopcart, respShopCartVo);
            respShopCartVo.setMarketPrice(RMBUtil.changeF2Y(Long.valueOf(shopcart.getMarketPrice())));
            respShopCartVo.setShopPrice(RMBUtil.changeF2Y(Long.valueOf(shopcart.getShopPrice())));
            respShopCartVo.setRealBuyPrice(RMBUtil.changeF2Y(Long.valueOf(shopcart.getRealBuyPrice())));
        }
        return respShopCartVo;
    }


}
